using huqiang.Core.HGUI;
using System;
using UnityEngine;
using System.IO;
using huqiang.Data;
using huqiang.UIModel;
using UnityEngine.Networking;
using System.Text;
using huqiang.UIEvent;
using huqiang.UIComposite;
using System.Collections.Generic;

public class HotData
{
    public bool hot;
    public byte[] dll;
    public byte[] ui;
    public byte[] pdb;
}
public class LoadingPage:UIPage
{
    static AssetBundle scene;
    //反射UI界面上的物体
    class View
    {
        public UIElement bg;
        public UIElement main;
        public UIElement down;
        public UIElement down2;
        public UserEvent menu;
        public UIElement open;
        public Text title;
        public UIElement Content;
        public UIElement Item;
        public UserEvent clear;
        public UserEvent Play;
        public UserEvent eye;
        public UserEvent eye1;
        public Slider slider;
        public Slider slider2;
        public NImage menu_icon;
        public UserEvent Change;
        public Text time;
        public UIElement right;
        public Text viceoCount;
        public Text offset;
        public UserEvent mask;
        public UserEvent eyeLeft;
        public UserEvent eyeRight;
        public ScrollY filelist;
    }
    View view;
    bool loadingScene;
    string nextPage;
    HotData hot;
    bool VersionValidat;
    int selectIndex=-1;
    class ScrollItem
    {
        public UserEvent but;
        public UIElement icon;
        public Text tips;
        public UserEvent del;
        public int index;
    }
    public override void Initial(UIElement parent, object dat = null)
    {
        base.Initial(parent, dat);
        LoadUI("playerpage");//"baseUI"创建的bytes文件名,"page"为创建的页面名
        view = new View();
        InitialEvent();
        InitialData();
    }
    void InitialEvent()
    {
        view.filelist.SetItemUpdate<ScrollItem, string>(ItemUpdate);
    }
    void ItemUpdate(ScrollItem item, string data, int index)
    {
        item.tips.text = data;
        if(selectIndex==index)
        {
            item.icon.activeSelf = true;
        }
        else
        {
            item.icon.activeSelf = false;
        }
        item.index = index;
        item.but.DataContext = item;
        item.but.Click = (o,e) => {
            var si = o.DataContext as ScrollItem;
            Debug.Log(si.index);
        };
        item.del.DataContext = item;
        item.del.Click = (o, e) => { 
        
        };
    }

    List<string> list;
    void InitialData()
    {
#if UNITY_EDITOR
        list = new List<string>();
        for (int i = 0; i < 300; i++)
            list.Add(i.ToString());
#endif
        view.filelist.BindingData = list;
        view.filelist.Refresh();
    }

    public override void Cmd(string cmd, object dat)
    {
    }

    float fill;
    bool loading;
    void SetProgress(float r)
    {
        fill = r;
        //view.FillImage.FillAmount = r;
        //float a = view.FillImage.SizeDelta.x;
        //view.Nob.localPosition = new Vector3((r - 0.5f) * a, 0, 0);
        //float t = 75 + (140 - 75) * (1 - r);
        //var col = Color.HSVToRGB(t / 255, 1, 1);
        //view.Nob.MainColor = col;
    }
    public override void Update(float time)
    {
        //AssetsAction.UpdateState();
        //var step = AssetsAction.GetCurrentStep();
        //if(step==null)
        //{
        //    LoadPage<HotFixPage>(hot);//将数据传入热更新管理页面
        //}
        //else
        //{
        //    view.Text.Text = step.Tips;
        //    SetProgress(step.Progress);
        //}
    }
}